package dbTools.tableInfo.info;

import java.util.Map;

import dbTools.tableInfo.ITableInfo;
import dbTools.tableInfo.field.Field;

public class TableInfo implements ITableInfo {

	private String tableId;
	
	private String tableName;
	
	private String key;
	
	private Map<String,Field> KeyFields;
	
	private Map<String,Field> AllFields;
	
	private Map<String,String> fieldsKeyForRef;

	public String getTableId() {
		return tableId;
	}

	public void setTableId(String tableId) {
		this.tableId = tableId;
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public Map<String, Field> getKeyFields() {
		return KeyFields;
	}

	public void setKeyFields(Map<String, Field> keyFields) {
		KeyFields = keyFields;
	}

	public Map<String, Field> getAllFields() {
		return AllFields;
	}

	public void setAllFields(Map<String, Field> allFields) {
		AllFields = allFields;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public Map<String, String> getFieldsKeyForRef() {
		return fieldsKeyForRef;
	}

	public void setFieldsKeyForRef(Map<String, String> fieldsKeyForRef) {
		this.fieldsKeyForRef = fieldsKeyForRef;
	}

	public Field findField(String key)
	{
		if(fieldsKeyForRef==null)
		{
			return null;
		}
		
		String fieldKey=fieldsKeyForRef.get(key);
		
		if(fieldKey==null)
		{
			return null;
		}
		return AllFields.get(fieldKey);
	}
	
	public String findSimpleRefDisplayName()
	{
		for(Map.Entry<String, Field> entry: this.AllFields.entrySet())
		{
			if(entry.getValue().getFieldName().contains("Name")
				||entry.getValue().getFieldName().contains("Nm"))
			{
				return entry.getValue().getFieldName();
			}
		}
		return "";
	}
	
	
}
